{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "30a5e37a-3301-49c6-befa-19f06153d7e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "import numpy as np\n",
    "import statsmodels.formula.api as smf\n",
    "from statsmodels.iolib.summary2 import summary_col\n",
    "\n",
    "thepath=os.getcwd()+r\"\\chip50_fordataverse.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d23be270-5f8f-470a-96c8-7f656c127509",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define a custom function to calculate weighted average\n",
    "def weighted_average(group,variables):\n",
    "    weight_sum=group[variables].apply(lambda x: np.where(pd.isna(x), 0, 1)).multiply(group['weight'], axis=0).sum()\n",
    "    weighted_variables = group[variables].multiply(group['weight'], axis=0)\n",
    "    weighted_average = weighted_variables.sum() / weight_sum\n",
    "    return weighted_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3d62cecd-6d0c-4aab-8186-73e7c9ec4fd7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Unnamed: 0', 'EndDate', 'weight', 'state', 'state_id', 'state_born',\n",
       "       'race_var', 'us_jobs_1', 'us_jobs_2', 'state_program',\n",
       "       'rand_program_name', 'sch_guideline_4', 'sch_guideline_5',\n",
       "       'sch_guideline_6', 'party', 'us_proud', 'us_close_1', 'us_close_2',\n",
       "       'us_imm'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chip50=pd.read_csv(thepath,na_values=-99) \n",
    "chip50.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "db2eac27-84fe-414d-b55e-4292740ddeb7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2024-11-09 15:11:02'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chip50.EndDate.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7371680f-2f79-4821-b341-3b71ee61a39a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2025-01-06 21:34:10'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chip50.EndDate.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "829a270e-5974-485b-9f49-b64b496ba8fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "# [us_jobs] Please indicate whether you agree or disagree with the following statements:\n",
    "# [us_jobs_1] When jobs are scarce, employers should give priority to local people over people\n",
    "# from other parts of the US.\n",
    "# [us_jobs_2] When jobs are scarce, employers should give priority to Americans over\n",
    "# immigrants.\n",
    "# 4 = Strongly agree\n",
    "# 3 = Agree\n",
    "# 2 = Disagree\n",
    "# 1 = Strongly disagree\n",
    "conditions=[\n",
    "    (chip50.us_jobs_1==1),\n",
    "    (chip50.us_jobs_1==2),\n",
    "    (chip50.us_jobs_1==3),\n",
    "    (chip50.us_jobs_1==4)\n",
    "]\n",
    "choices=[0,0,1,1]\n",
    "chip50['jobs_local01']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "conditions=[\n",
    "    (chip50.us_jobs_2==1),\n",
    "    (chip50.us_jobs_2==2),\n",
    "    (chip50.us_jobs_2==3),\n",
    "    (chip50.us_jobs_2==4)\n",
    "]\n",
    "chip50['jobs_ntnl01']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "\n",
    "conditions=[\n",
    "    (chip50.jobs_local01==0)&(chip50.jobs_ntnl01==0),\n",
    "    (chip50.jobs_local01==0)&(chip50.jobs_ntnl01==1),\n",
    "    (chip50.jobs_local01==1)&(chip50.jobs_ntnl01==0),\n",
    "    (chip50.jobs_local01==1)&(chip50.jobs_ntnl01==1),\n",
    "]\n",
    "choices=[1,0,0,0]\n",
    "chip50['neither']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,1,0,0]\n",
    "chip50['onlyntnl']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,0,1,0]\n",
    "chip50['onlylocal']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,0,0,1]\n",
    "chip50['both']=pd.to_numeric(np.select(conditions,choices,default=None))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8a528db2-9d29-4b2d-8899-9c30c034cf67",
   "metadata": {},
   "outputs": [],
   "source": [
    "#state_id = respondent's state\n",
    "#[state_born] In what state were you born? (0 = not in the US)\n",
    "conditions=[\n",
    "    (chip50['state_id']==chip50['state_born'])&(chip50['state_born']!=0),\n",
    "    (chip50['state_id']!=chip50['state_born'])&(chip50['state_born']!=0)\n",
    "]\n",
    "choices=[0,1]\n",
    "chip50['dommig']=pd.to_numeric(np.select(conditions,choices,default=None))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1aefcad3-e30d-4633-b3e5-89f4e3a3585a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# [us_proud] How proud are you to be of US nationality?\n",
    "# 5 = Very proud\n",
    "# 4 = Quite proud\n",
    "# 3 = Not very proud\n",
    "# 2 = Not at all proud\n",
    "# 1 = I am not of US nationality\n",
    "\n",
    "conditions=[\n",
    "    (chip50.us_proud==1),\n",
    "    (chip50.us_proud!=1)&(chip50.state_born==0),\n",
    "    (chip50.us_proud!=1)&(chip50.dommig==1)&(chip50.state_born!=0),\n",
    "    (chip50.us_proud!=1)&(chip50.dommig==0)&(chip50.state_born!=0)\n",
    "]\n",
    "choices=['NonNtnl','Ntrlzd','Dommig','Notdommig']\n",
    "chip50['migstatus2']=np.select(conditions,choices,default=None)\n",
    "choices=[1,1,0,0]\n",
    "chip50['bornabroad']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=['Nonntl','Ntrlzd','US Born','US Born']\n",
    "chip50['migstatus3']=np.select(conditions,choices,default=None)\n",
    "conditions=[\n",
    "    (chip50.us_proud==5),\n",
    "    (chip50.us_proud==4),\n",
    "    (chip50.us_proud==3),\n",
    "    (chip50.us_proud==2)\n",
    "]\n",
    "choices=[1,1,0,0]\n",
    "chip50['ntnlpride']=pd.to_numeric(np.select(conditions,choices,default=None))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9d31a947-3dcf-4681-822d-fc4cdbcbbe51",
   "metadata": {},
   "outputs": [],
   "source": [
    "# [sch_guideline] Now we would like you to consider general guidelines for scholarships.\n",
    "# [rand_program_name] gives financial aid to students planning to attend colleges and\n",
    "# universities in that state. If you were advising this award program, what requirements would\n",
    "# you recommend? Please indicate for each of the criteria below whether you would recommend\n",
    "# it be a requirement for a student to receive a scholarship, should be preferred but not required,\n",
    "# or should not be considered.\n",
    "# [sch_guideline_3] State residency\n",
    "# [sch_guideline_4] Attending or attended high school in the state\n",
    "# [sch_guideline_5] Member of a historically underprivileged race/ethnic group\n",
    "# [sch_guideline_6] US citizenship or permanent residence\n",
    "# 3 = Should be required\n",
    "# 2 = Should be preferred\n",
    "# 1 = Should not be considered\n",
    "conditions=[\n",
    "    chip50.sch_guideline_5==3,\n",
    "    chip50.sch_guideline_5==2,\n",
    "    chip50.sch_guideline_5==1\n",
    "]    \n",
    "choices=[1,1,0]\n",
    "chip50['RacialLiberal']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[1,0,0]\n",
    "chip50['URM_require']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,1,0]\n",
    "chip50['URM_prefer']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,0,1]\n",
    "chip50['URM_dont_consider']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "conditions=[\n",
    "    chip50.sch_guideline_4==3,\n",
    "    chip50.sch_guideline_4==2,\n",
    "    chip50.sch_guideline_4==1\n",
    "]    \n",
    "choices=[1,1,0]\n",
    "chip50['Residence_prefer_or_require']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[1,0,0]\n",
    "chip50['Residence_require']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,1,0]\n",
    "chip50['Residence_prefer']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "choices=[0,0,1]\n",
    "chip50['Residence_dont_consider']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "conditions=[\n",
    "    chip50.sch_guideline_4==3,\n",
    "    chip50.sch_guideline_4==2,\n",
    "    chip50.sch_guideline_4==1\n",
    "]\n",
    "choices=['Required','Preferred','Not considered']\n",
    "chip50['State_Residence_Criteria']=np.select(conditions,choices,default=None)\n",
    "conditions=[\n",
    "    chip50.sch_guideline_6==3,\n",
    "    chip50.sch_guideline_6==2,\n",
    "    chip50.sch_guideline_6==1\n",
    "]    \n",
    "choices=[1,0,0]\n",
    "chip50['Citizenship_require']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "conditions=[\n",
    "    (chip50['state_program']==chip50['rand_program_name']),\n",
    "    (chip50['state_program']!=chip50['rand_program_name'])\n",
    "]\n",
    "choices=[1,0]\n",
    "chip50['Own_state_program']=pd.to_numeric(np.select(conditions,choices,default=None))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f8837de4-c574-4976-9e88-e8941a737386",
   "metadata": {},
   "outputs": [],
   "source": [
    "# [party] Political party\n",
    "# • Republican\n",
    "# • Democrat\n",
    "# • Independent\n",
    "# • Other\n",
    "chip50.loc[chip50.party=='Other','party']=np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a67e1b85-0dac-4ede-99cd-ed70815bef4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# [us_close] People have different views about themselves and how they relate to the world.\n",
    "# How close do you feel to: -\n",
    "# [us_close_1] The US?\n",
    "# [us_close_2] The state where you live?\n",
    "# 4 = Very close\n",
    "# 3 = Close\n",
    "# 2 = Not very close\n",
    "# 1 = Not close at all\n",
    "\n",
    "conditions=[\n",
    "     (chip50['us_close_1']==chip50['us_close_2'])&(chip50['us_close_1']>2), # ~ \"Equalclose\",\n",
    "    (chip50['us_close_1']>chip50['us_close_2'])&(chip50['us_close_1']>2), # ~ \"CloserNtnl\",\n",
    "     (chip50['us_close_1']<chip50['us_close_2'])&(chip50['us_close_2']>2), # ~ \"CloserState\",\n",
    "    (chip50['us_close_1']<3)&(chip50['us_close_2']<3) # ~ \"Neither\"\n",
    "]\n",
    "choices=['Equally close US and state','Closer to US','Closer to state','Close to neither']\n",
    "chip50['feelclose']=np.select(conditions,choices,default=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4b73c734-a466-404a-9bcc-f013209e479e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# [us_imm] Do you think the number of immigrants to the United States nowadays should be:\n",
    "# 5 = Increased a lot\n",
    "# 4 = Increased a little\n",
    "# 3 = Remain the same as it is\n",
    "# 2 = Reduced a little\n",
    "# 1 = Reduced a lot\n",
    "conditions=[\n",
    "    chip50['us_imm']>=4,\n",
    "    chip50['us_imm']==3,\n",
    "    chip50['us_imm']<=2\n",
    "]\n",
    "choices=['More','Same','Less']\n",
    "chip50['immig']=np.select(conditions,choices,default=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b4e1b5c9-62c9-4a56-a9ba-f3a45a00bd0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>All respondents</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>onlylocal</th>\n",
       "      <th>neither</th>\n",
       "      <th>onlyntnl</th>\n",
       "      <th>both</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0.76554</td>\n",
       "      <td>0.737818</td>\n",
       "      <td>0.123666</td>\n",
       "      <td>0.138459</td>\n",
       "      <td>0.096314</td>\n",
       "      <td>0.641561</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   All respondents  jobs_local01  jobs_ntnl01  onlylocal   neither  onlyntnl  \\\n",
       "0                1       0.76554     0.737818   0.123666  0.138459  0.096314   \n",
       "\n",
       "       both  \n",
       "0  0.641561  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.5: All respondents\n",
    "chip50['All respondents']=1\n",
    "chip50.copy().groupby([\"All respondents\"]).apply(weighted_average,['jobs_local01','jobs_ntnl01','onlylocal','neither','onlyntnl','both'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6e889576-0b2e-4a14-8f07-2e706f0d8fb6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>race_var</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>onlylocal</th>\n",
       "      <th>neither</th>\n",
       "      <th>onlyntnl</th>\n",
       "      <th>both</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Asian</td>\n",
       "      <td>0.760377</td>\n",
       "      <td>0.675142</td>\n",
       "      <td>0.163557</td>\n",
       "      <td>0.161573</td>\n",
       "      <td>0.078634</td>\n",
       "      <td>0.596237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Black</td>\n",
       "      <td>0.776291</td>\n",
       "      <td>0.731765</td>\n",
       "      <td>0.132073</td>\n",
       "      <td>0.136527</td>\n",
       "      <td>0.087305</td>\n",
       "      <td>0.644095</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Latino</td>\n",
       "      <td>0.753666</td>\n",
       "      <td>0.663120</td>\n",
       "      <td>0.166965</td>\n",
       "      <td>0.169656</td>\n",
       "      <td>0.076906</td>\n",
       "      <td>0.586473</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>White</td>\n",
       "      <td>0.766777</td>\n",
       "      <td>0.763272</td>\n",
       "      <td>0.107585</td>\n",
       "      <td>0.129008</td>\n",
       "      <td>0.104554</td>\n",
       "      <td>0.658853</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  race_var  jobs_local01  jobs_ntnl01  onlylocal   neither  onlyntnl      both\n",
       "0    Asian      0.760377     0.675142   0.163557  0.161573  0.078634  0.596237\n",
       "1    Black      0.776291     0.731765   0.132073  0.136527  0.087305  0.644095\n",
       "2   Latino      0.753666     0.663120   0.166965  0.169656  0.076906  0.586473\n",
       "3    White      0.766777     0.763272   0.107585  0.129008  0.104554  0.658853"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.5: Respondents by race\n",
    "chip50.copy().groupby([\"race_var\"]).apply(weighted_average,['jobs_local01','jobs_ntnl01','onlylocal','neither','onlyntnl','both'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b8e5684e-5eb0-492e-af1c-6078ac1d672d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>party</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>onlylocal</th>\n",
       "      <th>neither</th>\n",
       "      <th>onlyntnl</th>\n",
       "      <th>both</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Democrat</td>\n",
       "      <td>0.735053</td>\n",
       "      <td>0.649180</td>\n",
       "      <td>0.161217</td>\n",
       "      <td>0.189665</td>\n",
       "      <td>0.075417</td>\n",
       "      <td>0.573701</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Independent</td>\n",
       "      <td>0.754188</td>\n",
       "      <td>0.720834</td>\n",
       "      <td>0.131326</td>\n",
       "      <td>0.148008</td>\n",
       "      <td>0.098141</td>\n",
       "      <td>0.622524</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Republican</td>\n",
       "      <td>0.815824</td>\n",
       "      <td>0.861722</td>\n",
       "      <td>0.070733</td>\n",
       "      <td>0.067322</td>\n",
       "      <td>0.117414</td>\n",
       "      <td>0.744531</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         party  jobs_local01  jobs_ntnl01  onlylocal   neither  onlyntnl  \\\n",
       "0     Democrat      0.735053     0.649180   0.161217  0.189665  0.075417   \n",
       "1  Independent      0.754188     0.720834   0.131326  0.148008  0.098141   \n",
       "2   Republican      0.815824     0.861722   0.070733  0.067322  0.117414   \n",
       "\n",
       "       both  \n",
       "0  0.573701  \n",
       "1  0.622524  \n",
       "2  0.744531  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.6: Respondents by partisanship\n",
    "chip50.copy().groupby([\"party\"]).apply(weighted_average,['jobs_local01','jobs_ntnl01','onlylocal','neither','onlyntnl','both'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4cf79263-ed3f-4c5e-903d-7b59fcc2e9ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ntnlpride</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>onlylocal</th>\n",
       "      <th>neither</th>\n",
       "      <th>onlyntnl</th>\n",
       "      <th>both</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.686738</td>\n",
       "      <td>0.551085</td>\n",
       "      <td>0.206537</td>\n",
       "      <td>0.242298</td>\n",
       "      <td>0.071458</td>\n",
       "      <td>0.479707</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.784880</td>\n",
       "      <td>0.783335</td>\n",
       "      <td>0.103251</td>\n",
       "      <td>0.113387</td>\n",
       "      <td>0.101961</td>\n",
       "      <td>0.681401</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ntnlpride  jobs_local01  jobs_ntnl01  onlylocal   neither  onlyntnl  \\\n",
       "0        0.0      0.686738     0.551085   0.206537  0.242298  0.071458   \n",
       "1        1.0      0.784880     0.783335   0.103251  0.113387  0.101961   \n",
       "\n",
       "       both  \n",
       "0  0.479707  \n",
       "1  0.681401  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.7: Respondents by national pride\n",
    "chip50.copy().groupby(['ntnlpride']).apply(weighted_average,['jobs_local01','jobs_ntnl01','onlylocal','neither','onlyntnl','both'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "cdb126cb-fee3-4cf7-bb0a-89d4b29989a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feelclose</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>onlylocal</th>\n",
       "      <th>neither</th>\n",
       "      <th>onlyntnl</th>\n",
       "      <th>both</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Close to neither</td>\n",
       "      <td>0.675620</td>\n",
       "      <td>0.570112</td>\n",
       "      <td>0.182586</td>\n",
       "      <td>0.247082</td>\n",
       "      <td>0.077895</td>\n",
       "      <td>0.492437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Closer to US</td>\n",
       "      <td>0.767591</td>\n",
       "      <td>0.782111</td>\n",
       "      <td>0.109409</td>\n",
       "      <td>0.108397</td>\n",
       "      <td>0.123886</td>\n",
       "      <td>0.658308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Closer to state</td>\n",
       "      <td>0.741055</td>\n",
       "      <td>0.634076</td>\n",
       "      <td>0.187857</td>\n",
       "      <td>0.177825</td>\n",
       "      <td>0.081473</td>\n",
       "      <td>0.552845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Equally close US and state</td>\n",
       "      <td>0.790444</td>\n",
       "      <td>0.784017</td>\n",
       "      <td>0.099721</td>\n",
       "      <td>0.116319</td>\n",
       "      <td>0.093573</td>\n",
       "      <td>0.690387</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    feelclose  jobs_local01  jobs_ntnl01  onlylocal   neither  \\\n",
       "0            Close to neither      0.675620     0.570112   0.182586  0.247082   \n",
       "1                Closer to US      0.767591     0.782111   0.109409  0.108397   \n",
       "2             Closer to state      0.741055     0.634076   0.187857  0.177825   \n",
       "3  Equally close US and state      0.790444     0.784017   0.099721  0.116319   \n",
       "\n",
       "   onlyntnl      both  \n",
       "0  0.077895  0.492437  \n",
       "1  0.123886  0.658308  \n",
       "2  0.081473  0.552845  \n",
       "3  0.093573  0.690387  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.7: Respondents by place feel closest to\n",
    "chip50.copy().groupby(['feelclose']).apply(weighted_average,['jobs_local01','jobs_ntnl01','onlylocal','neither','onlyntnl','both'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fe500a53-0956-451f-a351-2d629638d291",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>immig</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>onlylocal</th>\n",
       "      <th>neither</th>\n",
       "      <th>onlyntnl</th>\n",
       "      <th>both</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Less</td>\n",
       "      <td>0.814522</td>\n",
       "      <td>0.874596</td>\n",
       "      <td>0.061760</td>\n",
       "      <td>0.063551</td>\n",
       "      <td>0.122176</td>\n",
       "      <td>0.752513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>More</td>\n",
       "      <td>0.752688</td>\n",
       "      <td>0.638799</td>\n",
       "      <td>0.180044</td>\n",
       "      <td>0.181251</td>\n",
       "      <td>0.066527</td>\n",
       "      <td>0.572178</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Same</td>\n",
       "      <td>0.702994</td>\n",
       "      <td>0.603400</td>\n",
       "      <td>0.177005</td>\n",
       "      <td>0.219355</td>\n",
       "      <td>0.077871</td>\n",
       "      <td>0.525769</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  immig  jobs_local01  jobs_ntnl01  onlylocal   neither  onlyntnl      both\n",
       "0  Less      0.814522     0.874596   0.061760  0.063551  0.122176  0.752513\n",
       "1  More      0.752688     0.638799   0.180044  0.181251  0.066527  0.572178\n",
       "2  Same      0.702994     0.603400   0.177005  0.219355  0.077871  0.525769"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.7: Respondents by immigration policy preferences\n",
    "chip50.copy().groupby(['immig']).apply(weighted_average,['jobs_local01','jobs_ntnl01','onlylocal','neither','onlyntnl','both'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5a372d97-98a2-4e3c-8f21-cea3dd21402c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>All respondents</th>\n",
       "      <th>Residence_prefer_or_require</th>\n",
       "      <th>Residence_require</th>\n",
       "      <th>Residence_prefer</th>\n",
       "      <th>Residence_dont_consider</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0.730097</td>\n",
       "      <td>0.358789</td>\n",
       "      <td>0.371308</td>\n",
       "      <td>0.269903</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   All respondents  Residence_prefer_or_require  Residence_require  \\\n",
       "0                1                     0.730097           0.358789   \n",
       "\n",
       "   Residence_prefer  Residence_dont_consider  \n",
       "0          0.371308                 0.269903  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.8\n",
    "#State residency requirements: All respondents\n",
    "chip50.copy().groupby(['All respondents']).apply(weighted_average,['Residence_prefer_or_require','Residence_require','Residence_prefer','Residence_dont_consider'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1addd934-334f-4ad1-bd04-9503a4584b4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Own_state_program</th>\n",
       "      <th>Residence_prefer_or_require</th>\n",
       "      <th>Residence_require</th>\n",
       "      <th>Residence_prefer</th>\n",
       "      <th>Residence_dont_consider</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.722953</td>\n",
       "      <td>0.345648</td>\n",
       "      <td>0.377305</td>\n",
       "      <td>0.277047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0.751312</td>\n",
       "      <td>0.397815</td>\n",
       "      <td>0.353497</td>\n",
       "      <td>0.248688</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Own_state_program  Residence_prefer_or_require  Residence_require  \\\n",
       "0                  0                     0.722953           0.345648   \n",
       "1                  1                     0.751312           0.397815   \n",
       "\n",
       "   Residence_prefer  Residence_dont_consider  \n",
       "0          0.377305                 0.277047  \n",
       "1          0.353497                 0.248688  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.7\n",
    "#Own state versus other state's program - all respondents\n",
    "chip50.copy().groupby(['Own_state_program']).apply(weighted_average,['Residence_prefer_or_require','Residence_require','Residence_prefer','Residence_dont_consider'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c7e688d6-e41b-4e3d-89e4-42b4003ad62d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Own_state_program</th>\n",
       "      <th>race_var</th>\n",
       "      <th>Residence_prefer_or_require</th>\n",
       "      <th>Residence_require</th>\n",
       "      <th>Residence_prefer</th>\n",
       "      <th>Residence_dont_consider</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>Asian</td>\n",
       "      <td>0.756002</td>\n",
       "      <td>0.372598</td>\n",
       "      <td>0.383404</td>\n",
       "      <td>0.243998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>Black</td>\n",
       "      <td>0.756044</td>\n",
       "      <td>0.387152</td>\n",
       "      <td>0.368891</td>\n",
       "      <td>0.243956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>Latino</td>\n",
       "      <td>0.713739</td>\n",
       "      <td>0.319607</td>\n",
       "      <td>0.394132</td>\n",
       "      <td>0.286261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>White</td>\n",
       "      <td>0.715744</td>\n",
       "      <td>0.341473</td>\n",
       "      <td>0.374271</td>\n",
       "      <td>0.284256</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>Asian</td>\n",
       "      <td>0.801491</td>\n",
       "      <td>0.432280</td>\n",
       "      <td>0.369211</td>\n",
       "      <td>0.198509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>Black</td>\n",
       "      <td>0.782094</td>\n",
       "      <td>0.429026</td>\n",
       "      <td>0.353067</td>\n",
       "      <td>0.217906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>Latino</td>\n",
       "      <td>0.732889</td>\n",
       "      <td>0.356282</td>\n",
       "      <td>0.376607</td>\n",
       "      <td>0.267111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>White</td>\n",
       "      <td>0.744144</td>\n",
       "      <td>0.397954</td>\n",
       "      <td>0.346191</td>\n",
       "      <td>0.255856</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Own_state_program race_var  Residence_prefer_or_require  Residence_require  \\\n",
       "0                  0    Asian                     0.756002           0.372598   \n",
       "1                  0    Black                     0.756044           0.387152   \n",
       "2                  0   Latino                     0.713739           0.319607   \n",
       "3                  0    White                     0.715744           0.341473   \n",
       "4                  1    Asian                     0.801491           0.432280   \n",
       "5                  1    Black                     0.782094           0.429026   \n",
       "6                  1   Latino                     0.732889           0.356282   \n",
       "7                  1    White                     0.744144           0.397954   \n",
       "\n",
       "   Residence_prefer  Residence_dont_consider  \n",
       "0          0.383404                 0.243998  \n",
       "1          0.368891                 0.243956  \n",
       "2          0.394132                 0.286261  \n",
       "3          0.374271                 0.284256  \n",
       "4          0.369211                 0.198509  \n",
       "5          0.353067                 0.217906  \n",
       "6          0.376607                 0.267111  \n",
       "7          0.346191                 0.255856  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.7\n",
    "#Own state versus other state's program - respondents by race\n",
    "chip50.copy().groupby(['Own_state_program','race_var']).apply(weighted_average,['Residence_prefer_or_require','Residence_require','Residence_prefer','Residence_dont_consider'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "dccfadc3-460f-466d-a1e5-7e256deadc1c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Own_state_program</th>\n",
       "      <th>party</th>\n",
       "      <th>Residence_prefer_or_require</th>\n",
       "      <th>Residence_require</th>\n",
       "      <th>Residence_prefer</th>\n",
       "      <th>Residence_dont_consider</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>Democrat</td>\n",
       "      <td>0.715286</td>\n",
       "      <td>0.348153</td>\n",
       "      <td>0.367133</td>\n",
       "      <td>0.284714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>Independent</td>\n",
       "      <td>0.708579</td>\n",
       "      <td>0.305495</td>\n",
       "      <td>0.403084</td>\n",
       "      <td>0.291421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>Republican</td>\n",
       "      <td>0.760127</td>\n",
       "      <td>0.392483</td>\n",
       "      <td>0.367644</td>\n",
       "      <td>0.239873</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>Democrat</td>\n",
       "      <td>0.737239</td>\n",
       "      <td>0.394219</td>\n",
       "      <td>0.343021</td>\n",
       "      <td>0.262761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>Independent</td>\n",
       "      <td>0.723017</td>\n",
       "      <td>0.361668</td>\n",
       "      <td>0.361349</td>\n",
       "      <td>0.276983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>Republican</td>\n",
       "      <td>0.809199</td>\n",
       "      <td>0.453878</td>\n",
       "      <td>0.355321</td>\n",
       "      <td>0.190801</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Own_state_program        party  Residence_prefer_or_require  \\\n",
       "0                  0     Democrat                     0.715286   \n",
       "1                  0  Independent                     0.708579   \n",
       "2                  0   Republican                     0.760127   \n",
       "3                  1     Democrat                     0.737239   \n",
       "4                  1  Independent                     0.723017   \n",
       "5                  1   Republican                     0.809199   \n",
       "\n",
       "   Residence_require  Residence_prefer  Residence_dont_consider  \n",
       "0           0.348153          0.367133                 0.284714  \n",
       "1           0.305495          0.403084                 0.291421  \n",
       "2           0.392483          0.367644                 0.239873  \n",
       "3           0.394219          0.343021                 0.262761  \n",
       "4           0.361668          0.361349                 0.276983  \n",
       "5           0.453878          0.355321                 0.190801  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 3.7\n",
    "#Own state versus other state's program - respondents by party\n",
    "chip50.copy().groupby(['Own_state_program','party']).apply(weighted_average,['Residence_prefer_or_require','Residence_require','Residence_prefer','Residence_dont_consider'],include_groups=False).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1cd45ab5-8391-4747-905b-41aa2a1bd7aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Table A.5\n",
    "ui00=smf.ols(formula=\"sch_guideline_4 ~ Own_state_program\",data=chip50).fit()\n",
    "ui0=smf.ols(formula=\"sch_guideline_4 ~ Own_state_program + C(rand_program_name)+C(state)\",data=chip50).fit()\n",
    "ui1=smf.ols(formula=\"sch_guideline_4 ~ C(race_var)*Own_state_program + C(rand_program_name)+C(state)\",data=chip50).fit()\n",
    "ui2=smf.ols(formula=\"sch_guideline_4 ~ C(party)*Own_state_program + C(rand_program_name)+C(state)\",data=chip50).fit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "dfc14007-d257-47aa-b313-617670b5c918",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "=======================================================================================================================\n",
      "                                          sch_guideline_4 I sch_guideline_4 II sch_guideline_4 III sch_guideline_4 IIII\n",
      "-----------------------------------------------------------------------------------------------------------------------\n",
      "Own_state_program                         0.083***          0.082***           0.088**             0.070***            \n",
      "                                          (0.011)           (0.011)            (0.043)             (0.018)             \n",
      "C(race_var)[T.Black]:Own_state_program                                         -0.030                                  \n",
      "                                                                               (0.050)                                 \n",
      "C(race_var)[T.Latino]:Own_state_program                                        -0.022                                  \n",
      "                                                                               (0.052)                                 \n",
      "C(race_var)[T.White]:Own_state_program                                         0.004                                   \n",
      "                                                                               (0.045)                                 \n",
      "C(race_var)[T.Black]                                                           0.010                                   \n",
      "                                                                               (0.026)                                 \n",
      "C(race_var)[T.Latino]                                                          -0.068**                                \n",
      "                                                                               (0.026)                                 \n",
      "C(race_var)[T.White]                                                           -0.042*                                 \n",
      "                                                                               (0.023)                                 \n",
      "C(party)[T.Independent]                                                                            -0.035***           \n",
      "                                                                                                   (0.013)             \n",
      "C(party)[T.Republican]                                                                             0.091***            \n",
      "                                                                                                   (0.013)             \n",
      "C(party)[T.Independent]:Own_state_program                                                          0.006               \n",
      "                                                                                                   (0.027)             \n",
      "C(party)[T.Republican]:Own_state_program                                                           0.040               \n",
      "                                                                                                   (0.026)             \n",
      "R-squared                                 0.002             0.010              0.010               0.015               \n",
      "R-squared Adj.                            0.002             0.007              0.007               0.011               \n",
      "=======================================================================================================================\n",
      "Standard errors in parentheses.\n",
      "* p<.1, ** p<.05, ***p<.01\n"
     ]
    }
   ],
   "source": [
    "print(summary_col([ui00,ui0,ui1,ui2],stars=True,float_format='%0.3f',\n",
    "                  regressor_order=['Own_state_program','C(race_var)[T.Black]:Own_state_program',\n",
    "                                   'C(race_var)[T.Latino]:Own_state_program','C(race_var)[T.White]:Own_state_program',\n",
    "                                   'C(race_var)[T.Black]','C(race_var)[T.Latino]','C(race_var)[T.White]',\n",
    "                                   'C(party)[T.Independent]','C(party)[T.Republican]','C(party)[T.Independent]:Own_state_program','C(party)[T.Republican]:Own_state_program'\n",
    "                                  ],\n",
    "                  drop_omitted=True\n",
    "                  ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "85839aae-bb62-4f13-8986-7467ef6a5581",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>migstatus2</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>diff</th>\n",
       "      <th>race_var</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Dommig</td>\n",
       "      <td>0.730975</td>\n",
       "      <td>0.745161</td>\n",
       "      <td>-0.014186</td>\n",
       "      <td>All races</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NonNtnl</td>\n",
       "      <td>0.438107</td>\n",
       "      <td>0.629973</td>\n",
       "      <td>-0.191865</td>\n",
       "      <td>All races</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Notdommig</td>\n",
       "      <td>0.750595</td>\n",
       "      <td>0.781734</td>\n",
       "      <td>-0.031139</td>\n",
       "      <td>All races</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ntrlzd</td>\n",
       "      <td>0.692190</td>\n",
       "      <td>0.829630</td>\n",
       "      <td>-0.137439</td>\n",
       "      <td>All races</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  migstatus2  jobs_ntnl01  jobs_local01      diff   race_var\n",
       "0     Dommig     0.730975      0.745161 -0.014186  All races\n",
       "1    NonNtnl     0.438107      0.629973 -0.191865  All races\n",
       "2  Notdommig     0.750595      0.781734 -0.031139  All races\n",
       "3     Ntrlzd     0.692190      0.829630 -0.137439  All races"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 4.4 - US adults’ endorsement of national and sub-national hiring preferences, by respondent migration status\n",
    "fig42a=chip50.copy().groupby(['migstatus2']).apply(weighted_average,['jobs_ntnl01','jobs_local01'],include_groups=False).reset_index()\n",
    "fig42a['diff']=fig42a['jobs_ntnl01']-fig42a['jobs_local01']\n",
    "fig42a['race_var']='All races'\n",
    "fig42a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4de46d8d-90be-428f-902a-e12d801ce547",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>race_var</th>\n",
       "      <th>migstatus2</th>\n",
       "      <th>jobs_ntnl01</th>\n",
       "      <th>jobs_local01</th>\n",
       "      <th>diff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Asian</td>\n",
       "      <td>Dommig</td>\n",
       "      <td>0.702842</td>\n",
       "      <td>0.763253</td>\n",
       "      <td>-0.060411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Asian</td>\n",
       "      <td>NonNtnl</td>\n",
       "      <td>0.490349</td>\n",
       "      <td>0.682018</td>\n",
       "      <td>-0.191669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Asian</td>\n",
       "      <td>Notdommig</td>\n",
       "      <td>0.661167</td>\n",
       "      <td>0.768098</td>\n",
       "      <td>-0.106931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Asian</td>\n",
       "      <td>Ntrlzd</td>\n",
       "      <td>0.807281</td>\n",
       "      <td>0.795314</td>\n",
       "      <td>0.011967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Black</td>\n",
       "      <td>Dommig</td>\n",
       "      <td>0.715127</td>\n",
       "      <td>0.752894</td>\n",
       "      <td>-0.037768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Black</td>\n",
       "      <td>NonNtnl</td>\n",
       "      <td>0.483217</td>\n",
       "      <td>0.609826</td>\n",
       "      <td>-0.126610</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Black</td>\n",
       "      <td>Notdommig</td>\n",
       "      <td>0.746073</td>\n",
       "      <td>0.791157</td>\n",
       "      <td>-0.045085</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Black</td>\n",
       "      <td>Ntrlzd</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Latino</td>\n",
       "      <td>Dommig</td>\n",
       "      <td>0.685471</td>\n",
       "      <td>0.748118</td>\n",
       "      <td>-0.062647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Latino</td>\n",
       "      <td>NonNtnl</td>\n",
       "      <td>0.370292</td>\n",
       "      <td>0.645481</td>\n",
       "      <td>-0.275189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Latino</td>\n",
       "      <td>Notdommig</td>\n",
       "      <td>0.667583</td>\n",
       "      <td>0.762044</td>\n",
       "      <td>-0.094461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Latino</td>\n",
       "      <td>Ntrlzd</td>\n",
       "      <td>0.696358</td>\n",
       "      <td>0.824133</td>\n",
       "      <td>-0.127776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>White</td>\n",
       "      <td>Dommig</td>\n",
       "      <td>0.746898</td>\n",
       "      <td>0.740877</td>\n",
       "      <td>0.006021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>White</td>\n",
       "      <td>NonNtnl</td>\n",
       "      <td>0.453445</td>\n",
       "      <td>0.578372</td>\n",
       "      <td>-0.124926</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>White</td>\n",
       "      <td>Notdommig</td>\n",
       "      <td>0.777749</td>\n",
       "      <td>0.785351</td>\n",
       "      <td>-0.007602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>White</td>\n",
       "      <td>Ntrlzd</td>\n",
       "      <td>0.523684</td>\n",
       "      <td>0.831659</td>\n",
       "      <td>-0.307975</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   race_var migstatus2  jobs_ntnl01  jobs_local01      diff\n",
       "0     Asian     Dommig     0.702842      0.763253 -0.060411\n",
       "1     Asian    NonNtnl     0.490349      0.682018 -0.191669\n",
       "2     Asian  Notdommig     0.661167      0.768098 -0.106931\n",
       "3     Asian     Ntrlzd     0.807281      0.795314  0.011967\n",
       "4     Black     Dommig     0.715127      0.752894 -0.037768\n",
       "5     Black    NonNtnl     0.483217      0.609826 -0.126610\n",
       "6     Black  Notdommig     0.746073      0.791157 -0.045085\n",
       "7     Black     Ntrlzd     1.000000      1.000000  0.000000\n",
       "8    Latino     Dommig     0.685471      0.748118 -0.062647\n",
       "9    Latino    NonNtnl     0.370292      0.645481 -0.275189\n",
       "10   Latino  Notdommig     0.667583      0.762044 -0.094461\n",
       "11   Latino     Ntrlzd     0.696358      0.824133 -0.127776\n",
       "12    White     Dommig     0.746898      0.740877  0.006021\n",
       "13    White    NonNtnl     0.453445      0.578372 -0.124926\n",
       "14    White  Notdommig     0.777749      0.785351 -0.007602\n",
       "15    White     Ntrlzd     0.523684      0.831659 -0.307975"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 4.4 - US adults’ endorsement of national and sub-national hiring preferences, by respondent race and migration status\n",
    "fig42b=chip50.copy().groupby(['race_var','migstatus2']).apply(weighted_average,['jobs_ntnl01','jobs_local01'],include_groups=False).reset_index()\n",
    "fig42b['diff']=fig42b['jobs_ntnl01']-fig42b['jobs_local01']\n",
    "fig42b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "616d0edb-0a66-4f1d-9e14-0dc83f917dc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>race_var</th>\n",
       "      <th>jobs_ntnl01_Dommig</th>\n",
       "      <th>jobs_ntnl01_NonNtnl</th>\n",
       "      <th>jobs_ntnl01_Notdommig</th>\n",
       "      <th>jobs_ntnl01_Ntrlzd</th>\n",
       "      <th>Cf_Notdommig</th>\n",
       "      <th>Cf_Ntrlzd</th>\n",
       "      <th>Cf_Dommig</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>All races</td>\n",
       "      <td>0.730975</td>\n",
       "      <td>0.438107</td>\n",
       "      <td>0.750595</td>\n",
       "      <td>0.692190</td>\n",
       "      <td>-0.312488</td>\n",
       "      <td>-0.254083</td>\n",
       "      <td>-0.292868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Asian</td>\n",
       "      <td>0.702842</td>\n",
       "      <td>0.490349</td>\n",
       "      <td>0.661167</td>\n",
       "      <td>0.807281</td>\n",
       "      <td>-0.170817</td>\n",
       "      <td>-0.316931</td>\n",
       "      <td>-0.212493</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Black</td>\n",
       "      <td>0.715127</td>\n",
       "      <td>0.483217</td>\n",
       "      <td>0.746073</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.262856</td>\n",
       "      <td>-0.516783</td>\n",
       "      <td>-0.231910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Latino</td>\n",
       "      <td>0.685471</td>\n",
       "      <td>0.370292</td>\n",
       "      <td>0.667583</td>\n",
       "      <td>0.696358</td>\n",
       "      <td>-0.297291</td>\n",
       "      <td>-0.326066</td>\n",
       "      <td>-0.315179</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>White</td>\n",
       "      <td>0.746898</td>\n",
       "      <td>0.453445</td>\n",
       "      <td>0.777749</td>\n",
       "      <td>0.523684</td>\n",
       "      <td>-0.324304</td>\n",
       "      <td>-0.070238</td>\n",
       "      <td>-0.293452</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    race_var  jobs_ntnl01_Dommig  jobs_ntnl01_NonNtnl  jobs_ntnl01_Notdommig  \\\n",
       "0  All races            0.730975             0.438107               0.750595   \n",
       "1      Asian            0.702842             0.490349               0.661167   \n",
       "2      Black            0.715127             0.483217               0.746073   \n",
       "3     Latino            0.685471             0.370292               0.667583   \n",
       "4      White            0.746898             0.453445               0.777749   \n",
       "\n",
       "   jobs_ntnl01_Ntrlzd  Cf_Notdommig  Cf_Ntrlzd  Cf_Dommig  \n",
       "0            0.692190     -0.312488  -0.254083  -0.292868  \n",
       "1            0.807281     -0.170817  -0.316931  -0.212493  \n",
       "2            1.000000     -0.262856  -0.516783  -0.231910  \n",
       "3            0.696358     -0.297291  -0.326066  -0.315179  \n",
       "4            0.523684     -0.324304  -0.070238  -0.293452  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Figure 4.5 - \n",
    "def lookatdifference(dv,iv):\n",
    "    df=pd.concat([fig42a,fig42b],ignore_index=True)\n",
    "    df=df.pivot(index='race_var',columns='migstatus2',values=[dv]).reset_index()\n",
    "    df.columns = ['_'.join(str(x) for x in col_name).rstrip('_') if len(col_name)==2 else col_name for col_name in df.columns.to_flat_index()]\n",
    "    for x in ['NonNtnl','Notdommig','Ntrlzd','Dommig']:\n",
    "        if x!=iv:\n",
    "            df['Cf_'+x]=df[dv+'_'+iv]-df[dv+'_'+x]\n",
    "    return(df)\n",
    "lookatdifference('jobs_ntnl01','NonNtnl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "2b6db0d8-75a9-47a9-b9bb-d19a05712c16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>race_var</th>\n",
       "      <th>jobs_local01_Dommig</th>\n",
       "      <th>jobs_local01_NonNtnl</th>\n",
       "      <th>jobs_local01_Notdommig</th>\n",
       "      <th>jobs_local01_Ntrlzd</th>\n",
       "      <th>Cf_Notdommig</th>\n",
       "      <th>Cf_Ntrlzd</th>\n",
       "      <th>Cf_Dommig</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>All races</td>\n",
       "      <td>0.745161</td>\n",
       "      <td>0.629973</td>\n",
       "      <td>0.781734</td>\n",
       "      <td>0.829630</td>\n",
       "      <td>-0.151762</td>\n",
       "      <td>-0.199657</td>\n",
       "      <td>-0.115189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Asian</td>\n",
       "      <td>0.763253</td>\n",
       "      <td>0.682018</td>\n",
       "      <td>0.768098</td>\n",
       "      <td>0.795314</td>\n",
       "      <td>-0.086080</td>\n",
       "      <td>-0.113296</td>\n",
       "      <td>-0.081235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Black</td>\n",
       "      <td>0.752894</td>\n",
       "      <td>0.609826</td>\n",
       "      <td>0.791157</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.181331</td>\n",
       "      <td>-0.390174</td>\n",
       "      <td>-0.143068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Latino</td>\n",
       "      <td>0.748118</td>\n",
       "      <td>0.645481</td>\n",
       "      <td>0.762044</td>\n",
       "      <td>0.824133</td>\n",
       "      <td>-0.116563</td>\n",
       "      <td>-0.178653</td>\n",
       "      <td>-0.102637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>White</td>\n",
       "      <td>0.740877</td>\n",
       "      <td>0.578372</td>\n",
       "      <td>0.785351</td>\n",
       "      <td>0.831659</td>\n",
       "      <td>-0.206980</td>\n",
       "      <td>-0.253287</td>\n",
       "      <td>-0.162505</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    race_var  jobs_local01_Dommig  jobs_local01_NonNtnl  \\\n",
       "0  All races             0.745161              0.629973   \n",
       "1      Asian             0.763253              0.682018   \n",
       "2      Black             0.752894              0.609826   \n",
       "3     Latino             0.748118              0.645481   \n",
       "4      White             0.740877              0.578372   \n",
       "\n",
       "   jobs_local01_Notdommig  jobs_local01_Ntrlzd  Cf_Notdommig  Cf_Ntrlzd  \\\n",
       "0                0.781734             0.829630     -0.151762  -0.199657   \n",
       "1                0.768098             0.795314     -0.086080  -0.113296   \n",
       "2                0.791157             1.000000     -0.181331  -0.390174   \n",
       "3                0.762044             0.824133     -0.116563  -0.178653   \n",
       "4                0.785351             0.831659     -0.206980  -0.253287   \n",
       "\n",
       "   Cf_Dommig  \n",
       "0  -0.115189  \n",
       "1  -0.081235  \n",
       "2  -0.143068  \n",
       "3  -0.102637  \n",
       "4  -0.162505  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookatdifference('jobs_local01','NonNtnl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "ea2d3c2a-4e87-463f-8165-b990f6205a04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>URM_require</th>\n",
       "      <th>URM_prefer</th>\n",
       "      <th>URM_dont_consider</th>\n",
       "      <th>RacialLiberal</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>All respondents</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.141165</td>\n",
       "      <td>0.328063</td>\n",
       "      <td>0.530772</td>\n",
       "      <td>0.469228</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 URM_require  URM_prefer  URM_dont_consider  RacialLiberal\n",
       "All respondents                                                           \n",
       "1                   0.141165    0.328063           0.530772       0.469228"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Race liberalism descriptive statistics\n",
    "chip50.copy().groupby(['All respondents']).apply(weighted_average,['URM_require','URM_prefer','URM_dont_consider','RacialLiberal'],include_groups=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "ccd9d7e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>URM_require</th>\n",
       "      <th>URM_prefer</th>\n",
       "      <th>URM_dont_consider</th>\n",
       "      <th>RacialLiberal</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>race_var</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Asian</th>\n",
       "      <td>0.166990</td>\n",
       "      <td>0.400684</td>\n",
       "      <td>0.432327</td>\n",
       "      <td>0.567673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Black</th>\n",
       "      <td>0.234439</td>\n",
       "      <td>0.409949</td>\n",
       "      <td>0.355612</td>\n",
       "      <td>0.644388</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Latino</th>\n",
       "      <td>0.179004</td>\n",
       "      <td>0.382690</td>\n",
       "      <td>0.438306</td>\n",
       "      <td>0.561694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>White</th>\n",
       "      <td>0.110726</td>\n",
       "      <td>0.291378</td>\n",
       "      <td>0.597896</td>\n",
       "      <td>0.402104</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          URM_require  URM_prefer  URM_dont_consider  RacialLiberal\n",
       "race_var                                                           \n",
       "Asian        0.166990    0.400684           0.432327       0.567673\n",
       "Black        0.234439    0.409949           0.355612       0.644388\n",
       "Latino       0.179004    0.382690           0.438306       0.561694\n",
       "White        0.110726    0.291378           0.597896       0.402104"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Race liberalism descriptive statistics\n",
    "chip50.copy().groupby(['race_var']).apply(weighted_average,['URM_require','URM_prefer','URM_dont_consider','RacialLiberal'],include_groups=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "025abfb8-df02-404c-9103-5fe1459f9fbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Function to built figure 4.5 and 4.6 - Differences between racially liberal and racially conservative adults’ endorsement of preferences for locals by respondent race and migration status\n",
    "#Check the statistical significance of difference between racial liberals and conservatives\n",
    "def checkRacialLiberal(dv):\n",
    "    r0=smf.ols(formula=dv+\" ~ RacialLiberal\", data=chip50).fit()\n",
    "    r1=smf.ols(formula=dv+\" ~ RacialLiberal*C(race_var)*bornabroad\", data=chip50).fit()\n",
    "    #r2=smf.ols(formula=dv+\" ~ RacialLiberal*C(party)*bornabroad\", data=chip50).fit()\n",
    "    print(summary_col([r0,r1],stars=True))\n",
    "    print('')\n",
    "    print('Difference among Asian American born in US')\n",
    "    print(r1.t_test('RacialLiberal=0').summary_frame())\n",
    "    print('Difference among Asian American born abroad')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:bornabroad=0').summary_frame())\n",
    "    print('')\n",
    "    print('Difference among Black respondents born in US')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:C(race_var)[T.Black] =0').summary_frame())\n",
    "    print('Difference among Black respondents born abroad')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:C(race_var)[T.Black] + RacialLiberal:bornabroad+RacialLiberal:C(race_var)[T.Black]:bornabroad =0').summary_frame())\n",
    "    print('')\n",
    "    print('Difference among Latinx respondents born in US')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:C(race_var)[T.Latino] =0').summary_frame())\n",
    "    print('Difference among Latinx respondents born abroad')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:C(race_var)[T.Latino] + RacialLiberal:bornabroad+RacialLiberal:C(race_var)[T.Latino]:bornabroad =0').summary_frame())\n",
    "    print('')\n",
    "    print('Difference among White respondents born in US')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:C(race_var)[T.White] =0').summary_frame())\n",
    "    print('Difference among White respondents born abroad')\n",
    "    print(r1.t_test('RacialLiberal + RacialLiberal:C(race_var)[T.White] + RacialLiberal:bornabroad+RacialLiberal:C(race_var)[T.White]:bornabroad=0').summary_frame())\n",
    "    return([r0,r1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "725d0a5a-6990-4f67-ae3b-35590182281a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "=======================================================================================\n",
      "                                               Residence_require I Residence_require II\n",
      "---------------------------------------------------------------------------------------\n",
      "Intercept                                      0.3242***           0.3232***           \n",
      "                                               (0.0039)            (0.0178)            \n",
      "RacialLiberal                                  0.0835***           0.1020***           \n",
      "                                               (0.0057)            (0.0236)            \n",
      "C(race_var)[T.Black]                                               -0.0003             \n",
      "                                                                   (0.0210)            \n",
      "C(race_var)[T.Latino]                                              -0.0518**           \n",
      "                                                                   (0.0216)            \n",
      "C(race_var)[T.White]                                               0.0108              \n",
      "                                                                   (0.0183)            \n",
      "RacialLiberal:C(race_var)[T.Black]                                 0.0110              \n",
      "                                                                   (0.0275)            \n",
      "RacialLiberal:C(race_var)[T.Latino]                                0.0225              \n",
      "                                                                   (0.0287)            \n",
      "RacialLiberal:C(race_var)[T.White]                                 -0.0387             \n",
      "                                                                   (0.0247)            \n",
      "bornabroad                                                         -0.1192*            \n",
      "                                                                   (0.0707)            \n",
      "C(race_var)[T.Black]:bornabroad                                    0.0985              \n",
      "                                                                   (0.1022)            \n",
      "C(race_var)[T.Latino]:bornabroad                                   0.0234              \n",
      "                                                                   (0.0908)            \n",
      "C(race_var)[T.White]:bornabroad                                    0.0298              \n",
      "                                                                   (0.0863)            \n",
      "RacialLiberal:bornabroad                                           0.0544              \n",
      "                                                                   (0.0889)            \n",
      "RacialLiberal:C(race_var)[T.Black]:bornabroad                      -0.0531             \n",
      "                                                                   (0.1313)            \n",
      "RacialLiberal:C(race_var)[T.Latino]:bornabroad                     -0.0530             \n",
      "                                                                   (0.1221)            \n",
      "RacialLiberal:C(race_var)[T.White]:bornabroad                      -0.0348             \n",
      "                                                                   (0.1198)            \n",
      "R-squared                                      0.0075              0.0095              \n",
      "R-squared Adj.                                 0.0075              0.0090              \n",
      "=======================================================================================\n",
      "Standard errors in parentheses.\n",
      "* p<.1, ** p<.05, ***p<.01\n",
      "\n",
      "Difference among Asian American born in US\n",
      "        coef  std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.101992  0.02363  4.316169  0.000016        0.055676         0.148309\n",
      "Difference among Asian American born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.156383  0.085695  1.824892  0.068028       -0.011582         0.324349\n",
      "\n",
      "Difference among Black respondents born in US\n",
      "        coef   std err         t         P>|t|  Conf. Int. Low  \\\n",
      "c0  0.113003  0.014041  8.047884  8.747048e-16        0.085481   \n",
      "\n",
      "    Conf. Int. Upp.  \n",
      "c0         0.140524  \n",
      "Difference among Black respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.114341  0.095663  1.195252  0.231999       -0.073162         0.301845\n",
      "\n",
      "Difference among Latinx respondents born in US\n",
      "        coef   std err         t         P>|t|  Conf. Int. Low  \\\n",
      "c0  0.124483  0.016355  7.611532  2.791822e-14        0.092427   \n",
      "\n",
      "    Conf. Int. Upp.  \n",
      "c0         0.156539  \n",
      "Difference among Latinx respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.125912  0.082075  1.534114  0.125013       -0.034958         0.286782\n",
      "\n",
      "Difference among White respondents born in US\n",
      "        coef   std err       t         P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.063313  0.007344  8.6208  6.985374e-18        0.048918         0.077708\n",
      "Difference among White respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.082905  0.079943  1.037062  0.299716       -0.073786         0.239597\n"
     ]
    }
   ],
   "source": [
    "#Figure 4.5 - Differences between racially liberal and racially conservative adults’ endorsement of state residence requirement for scholarships, by respondent race and migration status\n",
    "res=checkRacialLiberal('Residence_require')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "89ee4af2-6246-4744-841a-a47958cce226",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "=============================================================================\n",
      "                                               jobs_local01 I jobs_local01 II\n",
      "-----------------------------------------------------------------------------\n",
      "Intercept                                      0.7426***      0.7284***      \n",
      "                                               (0.0034)       (0.0157)       \n",
      "RacialLiberal                                  0.0470***      0.0676***      \n",
      "                                               (0.0050)       (0.0209)       \n",
      "C(race_var)[T.Black]                                          -0.0049        \n",
      "                                                              (0.0186)       \n",
      "C(race_var)[T.Latino]                                         -0.0142        \n",
      "                                                              (0.0191)       \n",
      "C(race_var)[T.White]                                          0.0257         \n",
      "                                                              (0.0162)       \n",
      "RacialLiberal:C(race_var)[T.Black]                            0.0179         \n",
      "                                                              (0.0243)       \n",
      "RacialLiberal:C(race_var)[T.Latino]                           0.0092         \n",
      "                                                              (0.0254)       \n",
      "RacialLiberal:C(race_var)[T.White]                            -0.0385*       \n",
      "                                                              (0.0219)       \n",
      "bornabroad                                                    -0.1684***     \n",
      "                                                              (0.0619)       \n",
      "C(race_var)[T.Black]:bornabroad                               0.0585         \n",
      "                                                              (0.0894)       \n",
      "C(race_var)[T.Latino]:bornabroad                              0.0353         \n",
      "                                                              (0.0798)       \n",
      "C(race_var)[T.White]:bornabroad                               0.0313         \n",
      "                                                              (0.0758)       \n",
      "RacialLiberal:bornabroad                                      0.0585         \n",
      "                                                              (0.0781)       \n",
      "RacialLiberal:C(race_var)[T.Black]:bornabroad                 -0.0910        \n",
      "                                                              (0.1154)       \n",
      "RacialLiberal:C(race_var)[T.Latino]:bornabroad                0.0138         \n",
      "                                                              (0.1076)       \n",
      "RacialLiberal:C(race_var)[T.White]:bornabroad                 -0.0494        \n",
      "                                                              (0.1055)       \n",
      "R-squared                                      0.0031         0.0058         \n",
      "R-squared Adj.                                 0.0030         0.0052         \n",
      "=============================================================================\n",
      "Standard errors in parentheses.\n",
      "* p<.1, ** p<.05, ***p<.01\n",
      "\n",
      "Difference among Asian American born in US\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.067567  0.020878  3.236232  0.001213        0.026644         0.108489\n",
      "Difference among Asian American born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.126047  0.075254  1.674952  0.093955       -0.021454         0.273548\n",
      "\n",
      "Difference among Black respondents born in US\n",
      "        coef   std err         t         P>|t|  Conf. Int. Low  \\\n",
      "c0  0.085515  0.012405  6.893789  5.545110e-12        0.061202   \n",
      "\n",
      "    Conf. Int. Upp.  \n",
      "c0         0.109829  \n",
      "Difference among Black respondents born abroad\n",
      "       coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.05303  0.083986  0.631417  0.527773       -0.111587         0.217647\n",
      "\n",
      "Difference among Latinx respondents born in US\n",
      "        coef   std err         t         P>|t|  Conf. Int. Low  \\\n",
      "c0  0.076778  0.014458  5.310401  1.101986e-07        0.048439   \n",
      "\n",
      "    Conf. Int. Upp.  \n",
      "c0         0.105116  \n",
      "Difference among Latinx respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.149078  0.072538  2.055157  0.039873        0.006899         0.291256\n",
      "\n",
      "Difference among White respondents born in US\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.029093  0.006492  4.481187  0.000007        0.016368         0.041818\n",
      "Difference among White respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.038151  0.070654  0.539971  0.589221       -0.100334         0.176636\n"
     ]
    }
   ],
   "source": [
    "#Figure 4.5 - Differences between racially liberal and racially conservative adults’ endorsement of subnational hiring preferences, by respondent race and migration status\n",
    "lj=checkRacialLiberal('jobs_local01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "5a7ea198-7f1e-4e7a-9492-78d38d85c8c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===========================================================================================\n",
      "                                               Citizenship_require I Citizenship_require II\n",
      "-------------------------------------------------------------------------------------------\n",
      "Intercept                                      0.5374***             0.4066***             \n",
      "                                               (0.0040)              (0.0183)              \n",
      "RacialLiberal                                  -0.0559***            0.0164                \n",
      "                                               (0.0059)              (0.0244)              \n",
      "C(race_var)[T.Black]                                                 0.0804***             \n",
      "                                                                     (0.0217)              \n",
      "C(race_var)[T.Latino]                                                -0.0238               \n",
      "                                                                     (0.0223)              \n",
      "C(race_var)[T.White]                                                 0.1761***             \n",
      "                                                                     (0.0189)              \n",
      "RacialLiberal:C(race_var)[T.Black]                                   0.0230                \n",
      "                                                                     (0.0284)              \n",
      "RacialLiberal:C(race_var)[T.Latino]                                  0.0358                \n",
      "                                                                     (0.0297)              \n",
      "RacialLiberal:C(race_var)[T.White]                                   -0.1118***            \n",
      "                                                                     (0.0256)              \n",
      "bornabroad                                                           -0.2866***            \n",
      "                                                                     (0.0724)              \n",
      "C(race_var)[T.Black]:bornabroad                                      0.0951                \n",
      "                                                                     (0.1046)              \n",
      "C(race_var)[T.Latino]:bornabroad                                     0.0659                \n",
      "                                                                     (0.0933)              \n",
      "C(race_var)[T.White]:bornabroad                                      0.0549                \n",
      "                                                                     (0.0887)              \n",
      "RacialLiberal:bornabroad                                             0.2357***             \n",
      "                                                                     (0.0913)              \n",
      "RacialLiberal:C(race_var)[T.Black]:bornabroad                        -0.2206               \n",
      "                                                                     (0.1349)              \n",
      "RacialLiberal:C(race_var)[T.Latino]:bornabroad                       -0.2437*              \n",
      "                                                                     (0.1258)              \n",
      "RacialLiberal:C(race_var)[T.White]:bornabroad                        -0.0948               \n",
      "                                                                     (0.1234)              \n",
      "R-squared                                      0.0031                0.0202                \n",
      "R-squared Adj.                                 0.0031                0.0197                \n",
      "===========================================================================================\n",
      "Standard errors in parentheses.\n",
      "* p<.1, ** p<.05, ***p<.01\n",
      "\n",
      "Difference among Asian American born in US\n",
      "        coef  std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.016361  0.02443  0.669713  0.503046       -0.031522         0.064244\n",
      "Difference among Asian American born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.252093  0.088021  2.864013  0.004186        0.079568         0.424618\n",
      "\n",
      "Difference among Black respondents born in US\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.039382  0.014508  2.714493  0.006642        0.010945         0.067818\n",
      "Difference among Black respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.054545  0.098235  0.555256  0.578724       -0.137999          0.24709\n",
      "\n",
      "Difference among Latinx respondents born in US\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.052187  0.016913  3.085678  0.002033        0.019037         0.085337\n",
      "Difference among Latinx respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.044187  0.084845  0.520799  0.602511       -0.122113         0.210487\n",
      "\n",
      "Difference among White respondents born in US\n",
      "       coef   std err          t         P>|t|  Conf. Int. Low  \\\n",
      "c0 -0.09545  0.007599 -12.561622  4.273644e-36       -0.110344   \n",
      "\n",
      "    Conf. Int. Upp.  \n",
      "c0        -0.080557  \n",
      "Difference among White respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.045488  0.082641  0.550429  0.582029       -0.116492         0.207468\n"
     ]
    }
   ],
   "source": [
    "#Figure 4.6 - Differences between racially liberal and racially conservative adults’ endorsement of citizenship requirement for scholarships, by respondent race and migration status\n",
    "cit=checkRacialLiberal('Citizenship_require')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7a46f73d-7c0a-4254-a712-da5388fce345",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===========================================================================\n",
      "                                               jobs_ntnl01 I jobs_ntnl01 II\n",
      "---------------------------------------------------------------------------\n",
      "Intercept                                      0.7495***     0.6648***     \n",
      "                                               (0.0036)      (0.0161)      \n",
      "RacialLiberal                                  -0.0209***    0.0132        \n",
      "                                               (0.0052)      (0.0215)      \n",
      "C(race_var)[T.Black]                                         0.0284        \n",
      "                                                             (0.0191)      \n",
      "C(race_var)[T.Latino]                                        -0.0110       \n",
      "                                                             (0.0196)      \n",
      "C(race_var)[T.White]                                         0.1206***     \n",
      "                                                             (0.0167)      \n",
      "RacialLiberal:C(race_var)[T.Black]                           0.0503**      \n",
      "                                                             (0.0250)      \n",
      "RacialLiberal:C(race_var)[T.Latino]                          0.0321        \n",
      "                                                             (0.0261)      \n",
      "RacialLiberal:C(race_var)[T.White]                           -0.0608***    \n",
      "                                                             (0.0225)      \n",
      "bornabroad                                                   -0.2648***    \n",
      "                                                             (0.0636)      \n",
      "C(race_var)[T.Black]:bornabroad                              0.0034        \n",
      "                                                             (0.0920)      \n",
      "C(race_var)[T.Latino]:bornabroad                             0.0164        \n",
      "                                                             (0.0821)      \n",
      "C(race_var)[T.White]:bornabroad                              -0.0844       \n",
      "                                                             (0.0780)      \n",
      "RacialLiberal:bornabroad                                     0.1450*       \n",
      "                                                             (0.0804)      \n",
      "RacialLiberal:C(race_var)[T.Black]:bornabroad                -0.0236       \n",
      "                                                             (0.1187)      \n",
      "RacialLiberal:C(race_var)[T.Latino]:bornabroad               -0.1989*      \n",
      "                                                             (0.1107)      \n",
      "RacialLiberal:C(race_var)[T.White]:bornabroad                0.0527        \n",
      "                                                             (0.1086)      \n",
      "R-squared                                      0.0006        0.0162        \n",
      "R-squared Adj.                                 0.0005        0.0157        \n",
      "===========================================================================\n",
      "Standard errors in parentheses.\n",
      "* p<.1, ** p<.05, ***p<.01\n",
      "\n",
      "Difference among Asian American born in US\n",
      "        coef   std err        t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.013167  0.021489  0.61273  0.540059       -0.028952         0.055286\n",
      "Difference among Asian American born abroad\n",
      "       coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.15814  0.077425  2.042475  0.041114        0.006382         0.309897\n",
      "\n",
      "Difference among Black respondents born in US\n",
      "      coef  std err        t         P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.0635  0.01278  4.96885  6.773935e-07        0.038451         0.088549\n",
      "Difference among Black respondents born abroad\n",
      "        coef  std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.184848  0.08641  2.139207  0.032427        0.015481         0.354216\n",
      "\n",
      "Difference among Latinx respondents born in US\n",
      "        coef   std err        t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.045315  0.014891  3.04309  0.002344        0.016128         0.074503\n",
      "Difference among Latinx respondents born abroad\n",
      "       coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0 -0.00858  0.074632 -0.114965  0.908474       -0.154861         0.137701\n",
      "\n",
      "Difference among White respondents born in US\n",
      "        coef   std err         t         P>|t|  Conf. Int. Low  \\\n",
      "c0 -0.047678  0.006685 -7.131915  1.013318e-12       -0.060781   \n",
      "\n",
      "    Conf. Int. Upp.  \n",
      "c0        -0.034575  \n",
      "Difference among White respondents born abroad\n",
      "        coef   std err         t     P>|t|  Conf. Int. Low  Conf. Int. Upp.\n",
      "c0  0.150037  0.072693  2.063979  0.039029        0.007555         0.292518\n"
     ]
    }
   ],
   "source": [
    "#Figure 4.6 - Differences between racially liberal and racially conservative adults’ endorsement of national hiring preferences, by respondent race and migration status\n",
    "nj=checkRacialLiberal('jobs_ntnl01')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
